package com.ggj2013.hbh;

import com.ggj2013.hbh.utils.Tools;
import nme.display.MovieClip;
import nme.display.Shape;
import nme.text.Font;
import nme.text.TextFormat;
import nme.text.TextField;
import nme.text.TextFieldAutoSize;
import nme.text.TextFormatAlign;

/**
 * @author Jonathan Moriarty
 */
class ItemEvent extends MovieClip {
	
	private var _background:Shape;
	
	private var _decriptionDisplay:TextField;
	
	public static var descFont:Font;

	public var descFormat:TextFormat;
			
	public var remove:Bool;
	public var item:Item;
	
	public function new( l_item:Item ) {
		super();
		
		_background = new Shape();
		_background.graphics.beginFill( 0x000000 );
		_background.graphics.drawRect( 0, 0, HBH.STAGE_WIDTH, HBH.STAGE_HEIGHT );
		_background.graphics.endFill();
		_background.alpha = .5;
		addChild(_background);
		
		item = l_item;
		if ( descFont == null )
		{
			descFont = Tools.loadFont("jupiterc");
		}
		
		descFormat = new TextFormat( descFont.fontName, 24, 0xFFFFFF );
		descFormat.align = TextFormatAlign.CENTER;
		
		
		_decriptionDisplay = new TextField();
		_decriptionDisplay.defaultTextFormat = descFormat;
		_decriptionDisplay.selectable = false;
		_decriptionDisplay.embedFonts = true;
		_decriptionDisplay.text = l_item.description;
		_decriptionDisplay.autoSize = nme.text.TextFieldAutoSize.CENTER;
		_decriptionDisplay.x = HBH.STAGE_WIDTH / 2 - _decriptionDisplay.width / 2;
		_decriptionDisplay.y = HBH.STAGE_HEIGHT / 2  - _decriptionDisplay.height / 2;
		addChild( _decriptionDisplay );
		
	}
	
	public function update( l_deltaTime:Int ) {
		if ( InputManager.isKeyPressed( InputManager.E_KEY ) )
		{
			remove = true;
		}
	}		

}
